package nc.bs.pub.action;

import nc.bs.framework.common.NCLocator;
import nc.bs.pubapp.pf.action.AbstractPfAction;
import nc.bs.pubapp.pub.rule.UnapproveStatusCheckRule;
import nc.impl.pubapp.pattern.rule.processer.CompareAroundProcesser;
import nc.vo.pub.BusinessException;
import nc.vo.pub.VOStatus;
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
import nc.bs.qc.c012.ace.rule.CheckCanCancelApprove;
import nc.bs.qc.c012.plugin.bpplugin.Met_qc_checkbillPluginPoint;
import nc.vo.qc.c012.entity.AggMetCheckBillHeaderVO;
import nc.itf.qc.IMet_qc_checkbillMaintain;

public class N_C012_UNAPPROVE extends AbstractPfAction<AggMetCheckBillHeaderVO> {

	@Override
	protected CompareAroundProcesser<AggMetCheckBillHeaderVO> getCompareAroundProcesserWithRules(
			Object userObj) {
		CompareAroundProcesser<AggMetCheckBillHeaderVO> processor = new CompareAroundProcesser<AggMetCheckBillHeaderVO>(
				Met_qc_checkbillPluginPoint.UNAPPROVE);
		this.addBeforeRule(processor);

		return processor;
	}

	@Override
	protected AggMetCheckBillHeaderVO[] processBP(Object userObj,
			AggMetCheckBillHeaderVO[] clientFullVOs, AggMetCheckBillHeaderVO[] originBills) {
		for (int i = 0; clientFullVOs != null && i < clientFullVOs.length; i++) {
			clientFullVOs[i].getParentVO().setStatus(VOStatus.UPDATED);
		}
		AggMetCheckBillHeaderVO[] bills = null;
		try {
			IMet_qc_checkbillMaintain operator = NCLocator.getInstance()
					.lookup(IMet_qc_checkbillMaintain.class);
			bills = operator.unapprove(clientFullVOs, originBills);
		} catch (BusinessException e) {
			ExceptionUtils.wrappBusinessException(e.getMessage());
		}
		return bills;
	}
	
	
	private void addBeforeRule(CompareAroundProcesser<AggMetCheckBillHeaderVO> processor) {
		processor.addBeforeRule(new CheckCanCancelApprove());
		processor.addBeforeRule(new UnapproveStatusCheckRule());
		
	}

}
